"""
Library of column generators.

@author: Christophe Alexandre <optimacom.sarl at gmail dot com>

@license:
Copyright(C) 2010 Optimacom sarl

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/lgpl.txt>.
"""

def weight(src_column_name):
  def f(row):
    return None
  return f
  
def product(col_name1, col_name2):
  def f(row, c1=col_name1, c2=col_name2):
    p1 = row.get_column_position(c1)
    p2 = row.get_column_position(c2)
    v1 = row.get_row_position(p1)
    v2 = row.get_row_position(p2)
    if v1 is None or v2 is None:
      result = None
    else:
      result = v1 * v2
    return result
  return f

def constant(value):
  def f(row, v=value):
    return v
  return f